function my_eq (source_img)
src = imread(source_img);

%判断是否为彩色图片，如果是，则将其转为灰度图
if length(size(src))>2
    src = rgb2gray(src);
end

dst = src;

%获取图片尺寸，计算总像素数
[m,n] = size(src);

%生成一个1行256列的矩阵
numPix = zeros(1,256);

%统计各灰度的像素个数
for i = 0:255
    numPix(i+1) = length(find(src==i))/(m*n);
end

%累加概率值
probPix = zeros(1,256);
for i = 1:256
    for j = 1:i
        probPix(i) = numPix(j) + probPix(i);
    end
end

%映射灰度
newPix = round(probPix*255);
for i = 1:m
    for j = 1:n
        dst(i,j) = newPix(src(i,j)+1);
    end
end

figure(1)
subplot(121),imshow(uint8(src)),title('原始图像');
subplot(122),imshow(uint8(dst)),title('直方图均衡后的图像');
figure(2)
subplot(121),imhist(src,64),title('原始直方图');
subplot(122),imhist(dst,64),title('处理后的直方图');

clear;
%clc;

end